package plannegocio.web;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import plannegocio.excepcion.DAOExcepcion;
import plannegocio.negocio.GestionCategoria;
import plannegocio.negocio.GestionPersonas;
import plannegocio.negocio.GestionPlannegocios;
import plannegocio.modelo.*;

@Controller
public class PlanNegocioMantenimientoController {

	@RequestMapping(value = "/listarplannegocio")	
	protected ModelAndView ListarPlanNegocio(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		System.out.println("Hola mundoo");
		GestionPersonas negocio = new GestionPersonas();
		Collection<Sabio> lista = null;
		lista = negocio.listarSabio();
		
		System.out.println(lista.size());
		return new ModelAndView("PlanNegocioListar", "PLANESXSABIO", lista);
	}
	
	@RequestMapping(value = "/listarplansabio", method = RequestMethod.GET)
	protected ModelAndView PlanSabioListar(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		System.out.println("PLANSABIO LISTAR");
		PlanNegocio cat = new PlanNegocio();
		Sabio pe = new Sabio();
		GestionPlannegocios negocio = new GestionPlannegocios();
		Collection<PlanNegocio> lista = null;
		
		lista = negocio.listarxSabio(Integer.parseInt(request.getParameter("id")));
		
		pe.setPersonaID(Integer.parseInt(request.getParameter("id")));
		
		System.out.println(lista.size());
		
		if(lista.size()==0){
			cat.setoSabio(pe);
			lista.add(cat);
		}
		
		return new ModelAndView("PlanSabioListar", "PLANESXSABIO", lista);
	}
	
	@RequestMapping(value = "/anularplansabio", method = RequestMethod.GET)
	protected ModelAndView eliminarPlanSabio(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PlanNegocio pa = new PlanNegocio();
		GestionPlannegocios negocio = new GestionPlannegocios();

		pa= negocio.obtener_plannegocio(Integer.parseInt(request.getParameter("id")));
		System.out.println("Ver Eliminar PlanSabio");
		
		return new ModelAndView("PlanSabioEliminar", "PLANXSABIODEL", pa);
	}
}
